<?php namespace App\Http\Middleware;

use Closure, Auth, Redirect;

class Permission {

	/**
	 * Handle an incoming request.
	 *
	 * @param  \Illuminate\Http\Request  $request
	 * @param  \Closure  $next
	 * @return mixed
	 */
	public function handle($request, Closure $next){
		$user = Auth::user();
		if(!$user->hasPermission()){
			if($request->ajax()){
                exit(json_encode([
                    'status' => '-2',
                    'msg' => '未授权'
                ], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
			}else{
                exit('未授权');
			}
		}
		return $next($request);
	}

}
